#include <iostream>

using namespace std;

// 二分查找的实现
int binarySearch(int arr[],int length,int value)
{
    int left=0,right=length-1,mid=(left+right)/2;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(arr[mid]<value)
        {
            left=mid+1;
        }
        else if(arr[mid]>value)
        {
            right=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}

int main()
{
    int arr[8]={90,12,14,1,4,46,32,6};
    cout<<binarySearch(arr,8,46)<<endl;
}